// Parameters
var div_content = "content";
var div_blog_content = "blog_content";

// Get an element by id
function id(element_id) {
	return document.getElementById(element_id);
}

// Create a xlmHttp objet
function createXmlHttpObj () {
	var xmlHttp;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}
	return xmlHttp;
}

// GET html to fill a DIV
function ajaxGet(url, div){
	var xmlHttp = createXmlHttpObj();
	xmlHttp.onreadystatechange=function(){
		if(xmlHttp.readyState==1) {
			// display loading image here...
			var img_html = "<img src='images/loading.gif' alt='loading....' />";
			id(div).innerHTML=img_html;
		}
		if(xmlHttp.readyState==4) {
			id(div).innerHTML=xmlHttp.responseText;
		}
	}
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}


// Load blog(s)
function load_blog(div_content) {
	var blog_feed = new Array("http://cid-ac515e06b09543f0.users.api.live.net/Users(-6029935043246996496)/Main?$format=rss20",
	"http://xiaoyangde.blogspot.com/feeds/posts/default");
	var blog_title = new Array("MSN - Live Spaces","Google Blogger(Backup blog)");
	var blog_url = new Array("http://xiaoyangde.spaces.live.com",
	"http://xiaoyangde.blogspot.com");
	
	var html = '<div id="blog_list">';
	html += '<h3>My blog 我的博客 Mon blog</h3><ul>';
	for(var index=0; index<blog_feed.length; index++) {
		html += '<li>'+blog_title[index]+': <a href="'+blog_url[index]+'">'+blog_url[index]+'</a></li>';
	}
	html += '</ul></div>';
	html += '<div id="' + div_blog_content + '"></div>';
	id(div_content).innerHTML = html;
	
	var nb_blog_item = 5;
	var feedControl = new google.feeds.FeedControl();
	// Add all feeds with titles without the last one
	for(var index=0; index<blog_feed.length; index++) {
		feedControl.addFeed(blog_feed[index],blog_title[index]);
	}
	feedControl.setNumEntries(nb_blog_item);
	feedControl.setLinkTarget(google.feeds.LINK_TARGET_BLANK);
	feedControl.draw( id(div_blog_content) );
}
